package demo.gs.plugins;

import com.android.build.api.transform.DirectoryInput;
import com.android.build.api.transform.QualifiedContent;
import com.android.build.api.transform.Transform;
import com.android.build.api.transform.TransformException;
import com.android.build.api.transform.TransformInput;
import com.android.build.api.transform.TransformInvocation;
import com.android.build.api.transform.TransformOutputProvider;
import com.android.build.gradle.internal.LoggingUtil;
import com.android.build.gradle.internal.pipeline.TransformManager;

import org.gradle.api.Project;
import org.gradle.api.logging.LogLevel;
import org.gradle.api.logging.LoggingManager;

import java.io.IOException;
import java.util.Collection;
import java.util.Set;
import java.util.function.Consumer;

/**
 * <br>createBy Gw
 * <br>createTime: 2021/6/28 18:51
 */
public class ASMTransform extends Transform {

	private final Project mProject;

	public ASMTransform(Project project) {
		mProject = project;
	}

	@Override
	public String getName() {
		return "ASMTransform";
	}

	@Override
	public Set<QualifiedContent.ContentType> getInputTypes() {
		return TransformManager.CONTENT_CLASS;
	}

	@Override
	public Set<? super QualifiedContent.Scope> getScopes() {
		return TransformManager.SCOPE_FULL_PROJECT;
	}

	@Override
	public boolean isIncremental() {
		return false;
	}

	@Override
	public void transform(TransformInvocation invocation) throws TransformException, InterruptedException, IOException {
		//参考 https://blog.csdn.net/c10WTiybQ1Ye3/article/details/78098450
//		TransformOutputProvider outputProvider = invocation.getOutputProvider();
//		Collection<TransformInput> inputs = invocation.getInputs();
//
//		inputs.forEach(new Consumer<TransformInput>() {
//			@Override
//			public void accept(TransformInput input) {
//				input.getJarInputs()
//				input.getDirectoryInputs().forEach(new Consumer<DirectoryInput>() {
//					@Override
//					public void accept(DirectoryInput directoryInput) {
//						directoryInput.
//					}
//				});
//			}
//		});
//
//		outputProvider.getContentLocation()
//		String path = invocation.getContext().getPath();
//		mProject.getLogger().error("AMS-PLUGIN: " + path);
	}
}